/* eslint-disable no-bitwise */
/* eslint-disable no-underscore-dangle */
/* eslint-disable max-classes-per-file */
import { JsonProperty, Serializable } from '@/plugins/reflect-metadata';

@Serializable()
export class CardFaceItem {
  @JsonProperty('cardProductId')
    cardProductId: number = 0;

  @JsonProperty('faceValue')
    faceValue: number = 0;

  @JsonProperty('platformRecycleRate')
    _platformRecycleRate: number = 0;

  get platformRecycleRate() {
    const rateSplit = `${this._platformRecycleRate}`.split('.');
    const rate = rateSplit[1];
    if (rate.slice(2).length > 0) {
      return `${[...rate.slice(0, 2), '.', ...rate.slice(2)].join('')}折`;
    }
    return `${[...rate.slice(0, 2)].join('')}折`;
  }

  @JsonProperty('delFlag')
    delFlag: number = 0;

  get rateFee() {
    const rateSplit = `${this._platformRecycleRate}`.split('.');
    const rate = rateSplit[1];
    return (+rate * this.faceValue) / 10 ** rate.length;
  }
}

@Serializable()
export class CardInfoQuery {
  @JsonProperty('cardProductId')
    cardProductId: string = '';

  get body() {
    return {
      cardProductId: this.cardProductId,
    };
  }
}

@Serializable()
export class CardInfo {
  @JsonProperty('cardProductId')
    cardProductId: number = 0;

  @JsonProperty('cardProductName')
    cardProductName: string = '';

  @JsonProperty('cardProductType')
    cardProductType: string = '';

  @JsonProperty('formType')
    formType: number = 0;

  @JsonProperty('isMaintain')
    isMaintain: boolean = false;

  @JsonProperty('isUp')
    isUp: boolean = false;

  @JsonProperty('popular')
    popular: boolean = false;

  @JsonProperty('imageUrl')
    imageUrl: string = '';

  @JsonProperty('delFlag')
    delFlag: number = 0;

  @JsonProperty({ name: 'cardProductSkuVoList', type: CardFaceItem })
    items: CardFaceItem[] = [];
}

@Serializable()
export default class CardInstance {
  @JsonProperty({ name: 'data', type: CardInfo })
    data: CardInfo = new CardInfo();

  get total() {
    return this.data.items.length;
  }
}
